<?php
/**
 * @author Laurent SITTLER <lolo.sittler@gmail.com>
 * @author Alexandre GOMEZ <gomez.alexandre02@gmail.com>
 * @version 0.1
 */

/**
 * Controller Class
 */
class Controller {

    /**
     * Create Controller
     */
    function __construct() {
        $this->_Init();
    }

    /**
     * Init variables
     */
    protected function _Init() {
        $this->m_view = new View();
    }

    /**
     * Refresh View
     */
    function Update() {
        $this->view = $this->m_view;
        $this->view->render($this->m_view);
        $this->DestroyMessage();
    }

    /**
     * Load current model
     * @param String $model
     */
    public function LoadModel($name) {
        $path = 'Model/' . $name . '_Model.php';
        if (file_exists($path)) {
            require_once $path;
            $modelName = $name . '_Model';
            $this->model = new $modelName();
        }
    }
    
    /**
     * Destroy all user messages
     */
    private function DestroyMessage(){
        Session::Destroy(Constants::$SESSION_error);
        Session::Destroy(Constants::$SESSION_valid);
        Session::Destroy(Constants::$SESSION_currentTabs);
        Session::Destroy(Constants::$SESSION_sql);
        Session::Destroy(Constants::$SESSION_resultRequest);
    }

    /**
     * Get View
     * @return View
     */
    public function GetView() {
        return $this->m_view;
    }
    
    public function GetError(){
        return $this->m_error;
    }

    /**
     * Controller View
     * @var View View controller
     */
    private $m_view;

}